package alo.p10;

/**
 * @ClassName ShellSort
 * @Description 希尔排序
 * @Author Fanxc
 * @DATE 2021/3/11 14:54
 * @Version 1.0
 */
public class ShellSort {
    void shellSort(int[] A, int n) {
        int i, j, h, temp;
        h = 1;
        while (h < n / 3) h = 3 * h + 1;
        while (h >= 1) {
            for (i = h; i < n; i++) {
                for (j = i; j >= h && A[j - h] > A[j]; j -= h) {
                    temp = A[j - h];
                    A[j - h] = A[j];
                    A[j] = temp;
                }
            }
            h = h / 3;
        }
    }
}
